package com.scaffold.authority.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import wangjg.security.core.AuthoritySet;
import wangjg.security.http.HttpResource;


/**
 * 资源
 */
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Resource extends BasicBizEntity implements HttpResource, AuthoritySet{
	private static final long serialVersionUID = 1L;
	
	//http
	public static final int TYPE_HTTP = 1;
	
	@Id
	@GeneratedValue(strategy = IDENTITY)
	private Long id;
	//资源名称
	private String name;
	//资源标示
	@Column(name = "value")
	private String value;
	//资源类型 @ref #TYPE_*
	private Integer type;
	private String tag;
	/* 权限
	 * @ManyToMany Resource.id=ResourceAuthorityRelation.resourceId~ResourceAuthorityRelation.authorityId=Authority.id#name
	 */
	@Transient
	private Set<Authority> authorities;

	public Resource() {
	}

	public String getPattern() {
		return this.value;
	}

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getValue() {
		return this.value;
	}

	public void setValue(String value) {
		this.value = value;
	}
	
	public Set<Authority> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Set<Authority> authorities) {
		this.authorities = authorities;
	}

	public void setAuthorities(List<Authority> authorities) {
		this.authorities = new LinkedHashSet<Authority>(authorities);
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

}